<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
</head>
<body>
<div class="page-container">
    <div class="ibox float-e-margins">

        <div class="ibox-content">
            <div ><button class="all-kick  btn btn-warning  btn-sm">批量踢出</button></div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th><input id='checkAll' type="checkbox"></th>
                    <th>序号</th>
                    <th>用户ID</th>
                    <th>昵称</th>
                    <th>性别</th>
                    <th>头像</th>
                    <th>签名</th>
                    <th>生日</th>
                    <th>所在房间名</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="data" id="list" key="k"}
                <tr>
                    <input type="hidden" value="{$room_id}">
                    <td><input class='item' type="checkbox" value="{$list.id}"></td>
                    <td>{$k}</td>
                    <td>{$list.u_id}</td>
                    <td>{$list.nickname}</td>
                    <td>{$list.sex}</td>
                    <td><img src="{$list.pic}" style="width: 10%;"/></td>
                    <td>{$list.signature}</td>
                    <td>{$list.birthday}</td>
                    <td>{$room_id|get_room_name}</td>
                    <td><button  class="kick-user btn btn-warning  btn-sm">踢出房间</button></td>
                </tr>
                {/volist}
                </tbody>
            </table>
            {$data|raw}
        </div>
    </div>
</div>
{include file="common:footer"}
</body>
<script>

    $('.kick-user').click(function(){
        var room_id = $(this).parent().siblings().eq(0).val();
        var user_id = $(this).parent().siblings().eq(1).children(0).val();
        console.log(user_id);
        console.log(room_id);
        $.ajax({
            type: "get",
            url: "/KickUser",
            data:{
                user_id:user_id,
                room_id:room_id
            } ,
            dataType: 'json',
            success: function(re) {

                console.log(re[0]);
                if(re.code === 100) {
                    layer.msg(re.msg,{
                        icon:1,
                        time:1000
                    });
                    window.location.reload();
                }else{
                    layer.msg(re.msg,{
                        icon:2,
                        time:1000
                    });
                }
            },
            error: function (re) {
                console.log(re);
                layer.msg('踢出成功',{   //此处处理为特殊情况，不得已而为之
                    icon:1,
                    time:2500
                });
                window.location.reload();
            }
        });
    });

    var arr = [];
    $('#checkAll').click(function(){
        if($(this).prop('checked') === true){
            $('.item').prop('checked',true);
            $('.item:checked').each(function(){
                if(arr.indexOf($(this).val()) === -1)  //元素不存在为-1
                    arr.push($(this).val());
            });
        }else{
            $('.item').prop('checked',false);
            arr.splice(0,arr.length);
        }
        console.log(arr);
    });
    $('.item').click(function(){
        if($(this).prop('checked') === true){
            if(arr.indexOf($(this).val()) === -1)  //元素不存在为-1
                arr.push($(this).val());
        }else
            arr.splice(arr.indexOf($(this).val()),1);
        console.log(arr);
    });

    $('.all-kick').click(function(){

        var room_id = $('.kick-user').parent().siblings().eq(0).val();
        if(arr.length === 0)
            layer.msg('请勾选用户');
        else{
            layer.confirm('确认踢出吗',
                {
                    btn: ['确认', '取消'],
                    title: ['提示', 'font-size:18px;font-family:楷体;font-weight:700;']
                },function(){
                    $.ajax({
                        type:'get',
                        url:"/KickAllUser?user_id=" +arr+'&room_id='+room_id,
                        async:true,
                        dataType:'json',
                        success:function(result){
                            if(result.code === 100){
                                layer.msg(result.msg,{
                                    icon:1,
                                    time:2500
                                });
                                window.location.reload();
                            }
                            else{
                                layer.msg(result.msg,{
                                    icon:2,
                                    time:1000
                                });
                            }
                        },
                        error:function(err){
                            layer.msg('踢出成功',{
                                icon:1,
                                time:1000
                            });
                            window.location.reload();
                        }
                    });
                });
        }
    });

</script>
</html>